#!/usr/bin/python3
import sys

try:
    t = int(input())
    for x in range(t):
        n = int(input())
        if n < 1 or n > 100000:
            sys.exit(0)
        a = [int(item) for item in input().split()]
        s1 = [0]
        s2 = [0]
        for i in range(1, n + 1):
            s1.append(s1[i - 1] + a[i - 1])
            s2.append(s2[i - 1] + a[i - 1] * i)
        q = int(input())
        print("Case #%d: " % (x + 1))
        for i in range(q):
            lrs = input()
            lr = lrs.split()
            left = int(lr[0])
            right = int(lr[1])
            print(s2[right] - s2[left - 1] - ((s1[right] - s1[left - 1]) * (left - 1)))


except ValueError:
    pass
except IndexError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
